// 图片轮播通用函数
document.addEventListener('DOMContentLoaded', function() {
    // 初始化轮播
    const carousels = document.querySelectorAll('.carousel');
    carousels.forEach(carousel => {
        let current = 0;
        const images = carousel.querySelectorAll('img');
        const dots = carousel.querySelectorAll('.dot');
        const total = images.length;

        // 自动轮播
        setInterval(() => {
            images[current].classList.remove('active');
            dots[current].classList.remove('active');
            current = (current + 1) % total;
            images[current].classList.add('active');
            dots[current].classList.add('active');
        }, 5000);

        // 点击指示器切换图片
        dots.forEach((dot, index) => {
            dot.addEventListener('click', () => {
                images[current].classList.remove('active');
                dots[current].classList.remove('active');
                current = index;
                images[current].classList.add('active');
                dots[current].classList.add('active');
            });
        });
    });

    // 团队成员小导航栏切换
    const subNavLinks = document.querySelectorAll('.sub-navbar a');
    subNavLinks.forEach(link => {
        link.addEventListener('click', (e) => {
            e.preventDefault();
            subNavLinks.forEach(l => l.classList.remove('active'));
            link.classList.add('active');
        });
    });

    // 确保小导航栏在页面滚动时保持固定
    window.addEventListener('scroll', function() {
        const subNavbar = document.getElementById('sticky-sub-navbar');
        if (window.scrollY > 60) {
            subNavbar.style.position = 'fixed';
            subNavbar.style.top = '0';
            subNavbar.style.width = '100%';
            subNavbar.style.left = '0';
        } else {
            subNavbar.style.position = 'static';
        }
    });
});